package com.xuhai.blog19.common.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;


/**
 * @Author PangJunjie
 * @Date 2023/2/6/006
 */
@Configuration
public class KaptchaConfig {
    @Bean
    public DefaultKaptcha getDefaultKaptcha() {
        /*初始化验证码管理器*/
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        /*初始化配置类*/
        Properties properties = new Properties();
        properties.setProperty("kaptcha.border", "yes");/*验证码边框设置*/
        properties.setProperty("kaptcha.textproducer.font.color", "black");/*验证码文本颜色*/
        properties.setProperty("kaptcha.textproducer.char.length", "4");/*验证码长度*/
//        properties.setProperty("kaptcha.image.width", "100");
//        properties.setProperty("kaptcha.image.height", "40");
        /*初始化验证码配置类*/
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
